package cn.lanqiao.system.controller;


import cn.lanqiao.system.entity.Menu;
import cn.lanqiao.system.service.MenuService;
import cn.lanqiao.system.util.RedisUtilObject;
import cn.lanqiao.system.util.Result;
import cn.lanqiao.system.util.ZipFileDownloadUtils;
import cn.lanqiao.system.vo.UserVo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    MenuService menuService;


    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

//    @PostMapping("/list")
//    public Result getMenuList() {
//        List<Menu> menuList = null;
//        RedisUtilObject redis = new RedisUtilObject(redisTemplate);
//        if (redis.get("menuList") == null) {
//            menuList = menuService.getMenuList();
//            redis.set("menuList", menuList);
//        } else {
//            menuList = (List<Menu>) redis.get("menuList");
//        }
//        return Result.success(menuList);
//    }

    @Cacheable("menuList")
    @PostMapping("/list")
    public Result getMenuList() {
        return Result.success(menuService.getMenuList());
    }

    /**
     * 下载文件
     *
     */
    @GetMapping("/downLoadFile/{fileType}")
    public void downLoadFile( @PathVariable String fileType, HttpServletResponse response){
        Set<String> filePaths = new HashSet<>();
        filePaths.add("/Users/David/upload/2024-04-04/0be4974946084a4eb5692f69845afd7a.docx");
        filePaths.add("/Users/David/upload/2024-04-04/785f2504f05f42f6ac2c7ffc488480ff.docx");
        filePaths.add("/Users/David/upload/2024-04-01/7cf6fbbc9a8042f6bd2deef46ae50c11.docx");
        ZipFileDownloadUtils.zipFileDownloadByFile(filePaths,fileType,response);
    }


}
